using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Net.Mail;
using System.Net;
using System.Globalization;

namespace Sanchay
{
    class General
    {
        //Auto Generate mumber
        
        public void AutoNumberRowsForGridView(DataGridView dataGridView)
        {

            if (dataGridView != null)
            {

                for (int count = 0; (count <= (dataGridView.Rows.Count - 2)); count++)
                {

                    dataGridView.Rows[count].HeaderCell.Value = string.Format((count + 1).ToString(), "0");

                }

            }

        }

    
        public bool SendEmail(string attachmentFileName,string subject,string cc)
        {
            try
            {
                MailMessage message = new MailMessage();
                SmtpClient objSmtpClient = new SmtpClient("mail.easymci.org");
                message.From = new MailAddress("support@easymci.org");
                message.To.Add("ga7188@gmail.com");
                if (cc != "")
                {
                    message.CC.Add(cc);
                }
                message.Subject = "Sanchay-ErrorLog";
                Attachment objAttachment = new Attachment(attachmentFileName);
                message.Attachments.Add(objAttachment);
                //objSmtpClient.Port = 587;
                objSmtpClient.Credentials = new System.Net.NetworkCredential("support@easymci.org", "easymci123");
                //objSmtpClient.EnableSsl = true;
                bool mailSendStaus = false;
                objSmtpClient.Timeout = 900000;
                objSmtpClient.Send(message);
                objAttachment.Dispose();
                
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        
        /// <summary>
        /// Checks if Form is opened already or not
        /// </summary>
        /// <param name="targetFormName">{string} Form Name</param>
        /// <returns>true/false</returns>
        public static bool isOpened(string targetFormName)
        {
            foreach (Form f in Application.OpenForms)
            {
                if (f.Name == targetFormName)
                {
                    return true;
                }
            }
            return false;
        }

        public static string ChangeIntoIndianCurrencyFormat(decimal amount)
        {
            NumberFormatInfo nfi = CultureInfo.GetCultureInfo("hi-IN").NumberFormat;
            nfi = (NumberFormatInfo)nfi.Clone();
            nfi.CurrencySymbol = "";
            nfi.CurrencyPositivePattern = 0;
            return string.Format(nfi, "{0:c}", amount);
        }

      
    }
}
